//
//  KosspotApp.swift
//  Kosspot
//
//  Created by 胡辉 on 2025/6/17.
//

import SwiftUI
import UTEBluetoothRYApi

@main
struct KosspotApp: App {
    @StateObject private var appState = AppState.shared
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(appState)
        }
    }
}

struct ContentView: View {
    @EnvironmentObject var appState: AppState
    
    var body: some View {
        NavigationStack(path: $appState.navigationPath) {
            VStack {
                if appState.isLoggedIn {
                    KosspotTabBarView()
                } else {
                    PhoneLoginView()
                }
            }
            .navigationDestination(for: AppRoute.self) { route in
                switch route {
                case .home:
                    KosspotTabBarView()
                case .profile:
                    ProfileView()
                case .resetPassword:
                    ResetPasswordView()
                case .fitnessListDetail(let id):
                    FitnessListDetail(item: id)
                case .setting:
                    SettingView()
                case .privacy(let id):
                    PrivacyView(url: id)
                case .agreement:
                    AgreementView()
                case .feedback:
                    FeedbackView()
                case .abouturs:
                    AboutUrsView()
                case .phonelogin:
                    PhoneLoginView()
                case .passwordlogin:
                    PasswordLoginView()
                case .nochecklogin:
                    NoCheckLonginView()
                case .tabbar:
                    KosspotTabBarView()
                case .usrinfo:
                    UserInfoView()
                case .register:
                    RegisterView()
                case .fitnessList:
                    FitnessListView()
                case .postSportMoment:
                    PostSportMomentView()
                case .dynamicMoment:
                    DynamicMomentView()
                case .scanDevice:
                    ScanDevice(appState: appState)
                case .sportCircleDetail(let id):
                    SportCircleDetail(dynamicitem:id)
                case .deviceList:
                    DeviceListView()
                case .deviceSetting(id: let id):
                    DeviceSettingView(item:.constant(id))
                case .messagepush:
                    MessagePushView()
                case .electroniccard:
                    ElectronicCardView()
                case .clocksetting(let id, let id1):
                    ClockSettingView(alarm: .constant(id),isEdit:id1)
                case .otherSetting:
                    OtherSettingView()
                case .firmupdate:
                    FirmwareUpdateView()
                case .deviceDetail(let device):
                    DeviceDetailView(device: device)
                case .clocklist:
                    ClockListView()
                case .cycleCalender:
                    CycleCalendarView()
                case .takePhote:
                    TakePhotoView()
                case .cycleCalendarNotify:
                    CycleCalendarNotifyView()
                case .cycleCalendarSetting:
                    CycleCalendarSettingView()
                case .cardEdit:
                    CardEditView().environmentObject(CardStore())
                case .bloodOxygenDetail:
                    BloodOxygenDetailView()
                case .heartRateDetail:
                    HeartRateDetailView()
                case .sleepQualityDetail:
                    SleepQualityDetailView()
                case .weightDetail:
                    WeightDetailView()
                case .stressDetail:
                    StressDetailView()
                case .bindPhoneNumber(accessToken:let accessToken,openid: let openid, unionid: let unionid):
                    BindPhoneNumberView(accessToken:accessToken,openid:openid,unionid:unionid)
                case .drinkReminder:
                    DrinkReminderView()
                }
            }
        }
    }
}

